import { g_db } from 'db/state';

const ck_test_val = (step, pre="") => {
    let w = parseFloat(step[`${pre}width`]);
    let d = parseFloat(step[`${pre}dia`]);

    if (isNaN(w) || isNaN(d)) {
        return [null, null];
    }

    w = w.toFixed(0);
    d = d.toFixed(0);

    return [w, d];
};

const ck_tech = () => {
    const w = g_db.out_w_tech() * 1000;
    if (isNaN(w)) {
        return ["请设置宽度公称值", null, null];
    }

    const d = g_db.out_dia_tech() * 1000;
    if (isNaN(d)) {
        return ["请设置外圆公称值", null, null];
    }

    return [null, w, d];
};

const ck_zero = () => {
    const w = g_db.out_w_zero() * 1000;
    if (isNaN(w)) {
        return ["请设置宽度校零值", null, null];
    }

    const d = g_db.out_dia_zero() * 1000;
    if (isNaN(d)) {
        return ["请设置外圆校零值", null, null];
    }

    return [null, w, d];
};

const ck_std = () => {
    const w = g_db.out_w_std();
    if (isNaN(w)) {
        return ["请标定宽度", null, null];
    }

    const d = g_db.out_dia_std();
    if (isNaN(d)) {
        return ["请标定外圆", null, null];
    }

    return [null, w, d];
};

const ck_w_range = () => {
    const w = g_db.out_w_up() * 1000;
    if (isNaN(w)) {
        return ["请设定宽度上限", null, null];
    }

    const d = g_db.out_w_down() * 1000;
    if (isNaN(d)) {
        return ["请设定宽度下限", null, null];
    }

    return [null, w, d];
};

const ck_dia_range = () => {
    const w = g_db.out_dia_up() * 1000;
    if (isNaN(w)) {
        return ["请设定外圆上限", null, null];
    }

    const d = g_db.out_dia_down() * 1000;
    if (isNaN(d)) {
        return ["请设定外圆下限", null, null];
    }

    return [null, w, d];
};

export {ck_test_val, ck_tech, ck_zero, ck_std, ck_w_range, ck_dia_range};
